package edu.gyc.hiwhore.controller;


import edu.gyc.hiwhore.model.Girl;
import edu.gyc.hiwhore.service.GirlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 * https://blog.csdn.net/qq_38974634/article/details/80650810?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-2.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-2.control
 *https://segmentfault.com/a/1190000025216273
 * https://cloud.tencent.com/developer/article/1824707
 * @author ls
 * @since 2021-08-03
 */
@RestController
@RequestMapping("/girl")
public class GirlController {

    @Autowired
    GirlService girlService;


    @GetMapping("/{id}")
    public Object getGirlById(@PathVariable("id") Integer id) {
        Girl girl = girlService.getById(id);
        return girl;
    }

    @GetMapping("/update")
    public Object updateGirlById(Girl girl) {
      boolean ok=  girlService.updateById(girl);
        if (ok) {
            return girlService.getById(girl.getId());
        }else {
          return   "Id "+girl.getId()+" 有误，无法更新！";
        }

    }
    @PostMapping("/update")
    public Object updateGirlByIdPost(Girl girl) {
        Girl girl1=   girlService.update(girl);

            return girl1;


    }

    @GetMapping("/del/{id}")
    public Object delGirlById(@PathVariable("id") Integer id) {
        boolean r = girlService.del(id);
        String msg=r?"del ok ":"del fail ";
        msg+=id;
        return msg;
    }

    @GetMapping("/list")
    public Object getall() {

        return girlService.allGirls();
    }
}
